<?php 
//Fisier inclus pentru restrictionare.

function verificare_cladire($id, $nivel, $planeta) {
$q_res = mysql_fetch_row(mysql_query("SELECT minerale, gaz, energie FROM planete WHERE id = '".$planeta."'"));
$minerale = $q_res[0];
$gaz = $q_res[1];
$energie = $q_res[2];
$populatie = NULL;
$query = mysql_query("SELECT `nr` FROM unitati WHERE planeta = '".$planeta."'");
$populatie = returnare_populatie($planeta) + returnare_populatie_extra($planeta);
$nivel_depozit_aprovizionare = mysql_fetch_row(mysql_query("SELECT nivel FROM cladiri WHERE nume = '3' AND planeta = '".$planeta."'"));
if ($nivel_depozit_aprovizionare > 0)
 $max_populatie = round(formula_incrementare(20, $nivel_depozit_aprovizionare[0], '2.5', ''));
 else
 $max_populatie = 0;
$max_populatie += 20;

$query_restrictii = mysql_query("SELECT * FROM c_cladiri WHERE id = '".$id."'");
 while($rez_restrictii = mysql_fetch_array($query_restrictii)) {
$cost_minerale = $rez_restrictii["cost_minerale"];
$cost_gaz = $rez_restrictii["cost_gaz"];
$cost_energie = $rez_restrictii["cost_energie"];
$cost_populatie = $rez_restrictii["cost_populatie"];
$form_inc_minerale = $rez_restrictii["form_inc_minerale"];
$form_inc_gaz = $rez_restrictii["form_inc_gaz"];
$form_inc_energie = $rez_restrictii["form_inc_energie"];
$form_inc_populatie = $rez_restrictii["form_inc_populatie"];
$nivel_maxim = $rez_restrictii["nivel_maxim"];
}
	
$cost_minerale_nivel = round(formula_incrementare($cost_minerale, $nivel, $form_inc_minerale, ""), -1);
$cost_gaz_nivel = round(formula_incrementare($cost_gaz, $nivel, $form_inc_gaz, ""), -1);
$cost_energie_nivel = round(formula_incrementare($cost_energie, $nivel, $form_inc_energie, ""), -1);
$cost_populatie_nivel = round(formula_incrementare($cost_populatie, $nivel, $form_inc_populatie, ""));
$nr_populatie = $cost_populatie_nivel + $populatie;

if ($nivel >= $nivel_maxim)
 return 'Cladire extinsa complet';

if ($cost_minerale_nivel > $minerale)
 return 'Nu aveti destule minerale';
 
if ($cost_gaz_nivel > $gaz)
 return 'Nu aveti destul gaz';

if ($nr_populatie > $max_populatie)
 return 'Nu aveti destule locuri libere';
 
if (($cost_minerale_nivel <= $minerale) && ($cost_gaz_nivel <= $gaz) && ($nr_populatie <= $max_populatie))
 return 1;
else
 return 'Nu aveti destule resurse';
}

?>